<template>
  <div class="">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="顶级分类" prop="region">
        <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
          <el-option
            v-for="item in gettopCategory"
            :key="item.id"
            :label="item.name"
            value="shanghai"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="分类名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <!-- 上传图片 -->
      分类图片
      <el-upload
        class="avatar-uploader"
        action="http://kumanxuan1.f3322.net:8360/admin/upload/goodNewPic"
        :headers="headers"
        name="good_pic"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
         <div>
      显示
      <el-switch
        v-model="value"
        active-color="#13ce66"
        inactive-color="#ff4949"
      >
      </el-switch>
      </div>
      <!-- 排序 -->
      <div>
        <el-form-item label="排序" prop="name">
          <el-input v-model="Paixu.name"></el-input>
        </el-form-item>
        <!-- 分类描述 -->
      <el-form-item label="分类描述" prop="desc">
    <el-input type="textarea" v-model="ruleForm.desc"></el-input>
  </el-form-item>
  <!-- 按钮 -->
   <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
    <el-button @click="resetForm('ruleForm')">取消</el-button>
  </el-form-item>
    </div>
    </el-form>
    <!-- 显示 -->
 
  </div>
</template>
 
<script>
import { gettopCategory,getCategoryStore } from "../../../../../request/api";
export default {
  data() {
    return {
      gettopCategory: [],
      imageUrl: "",
      headers: {
        "X-Nideshop-Token": localStorage.getItem("token"),
      },
      value: true,
      ruleForm: {
        region: "",
        name: "",
      },
      rules: {
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" },
        ],
      },
       Paixu: {
        name: "",
      },
    };
  },
  created() {
    gettopCategory().then((res) => {
      this.gettopCategory = res.data;
      console.log(this.gettopCategory);
    });
  },
  methods: {
    handleAvatarSuccess(res, file) {
      
      if (res.errno == 0) {
        this.imageUrl = res.data.fileUrl;
      }
    },
    beforeAvatarUpload(file) {},
    handleClick(scope) {},
    submitForm(id){
      //分类名称
      console.log( this.ruleForm.name);
      //分类级别
      console.log(this.ruleForm.region);
       getCategoryStore({
         font_name:this.ruleForm.name,
         is_show:this.value,
        front_desc:this.ruleForm.region,
        parent_id:this.Paixu.name,
        sort_order:0,
        wap_banner_url:this.imageUrl
       }).then((res)=>{
         console.log(res);
       })
    }
  },
};
</script>
 
<style lang = "less" scoped>
.el-form-item {
  width: 300px;
  height: 100px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>